package com.lyj.mode.flyWeight;

import java.util.HashMap;

/**
 * 享元工厂类
 * @author:liyajie
 * @createTime:2022/3/3 11:39
 * @version:1.0
 */
public class WebsiteFactory {
    // 创建HashMap,充当池的角色
    private HashMap<String, ConcreteWebsite> pool = new HashMap<String, ConcreteWebsite>();

    // 根据类型判断，获取池子里的对象
    public Website getWebsite(String type){
        if(!pool.containsKey(type)){
            pool.put(type,new ConcreteWebsite(type));
        }
        return pool.get(type);
    }

    // 获取池子里的对象总数
    public int getWebsiteCount(){
        System.out.println("当前池子里的对象总数：" + pool.size());
        return pool.size();
    }
}
